﻿using Entity.Models.Entities;
using IDAL;
using Microsoft.EntityFrameworkCore;
using RepositorySys.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using utils;

namespace DAL
{
    /// <summary>
    /// 用户数据访问层
    /// </summary>
    public class UserDAL : IUserDAL
    {
        RepositorySysContext _repositorySys;

        public UserDAL(RepositorySysContext repositorySys)
        {
            _repositorySys = repositorySys;
        }


        /// <summary>
        /// 查询用户所有数据
        /// </summary>
        /// <returns></returns>
        public DbSet<UserInfo> getUserShowDAL()
        {
            return _repositorySys.UserInfos;
        }


        /// <summary>
        /// 添加信息
        /// </summary>
        /// <param name="userInfo"></param>
        public int AddUserDAL(UserInfo userInfo)
        {
            _repositorySys.UserInfos.Add(userInfo);
            return _repositorySys.SaveChanges();

        }

        /// <summary>
        /// 删除信息
        /// </summary>
        /// <param name="userId"></param>
        public int DatateUserDAL(string userId)
        {
            UserInfo userInfo = _repositorySys.UserInfos.Find(userId);
            if (userInfo != null)
            {
                userInfo.IsDelete = true;
                userInfo.DeleteTime = DateTime.Now;
                _repositorySys.UserInfos.Update(userInfo);
            }
            return _repositorySys.SaveChanges();
        }


        /// <summary>
        /// 更新信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int UpdateUserDAL(UserInfo user)
        {
            _repositorySys.UserInfos.Update(user);
            return _repositorySys.SaveChanges();
        }

      
    }
}
